package com.xca.is.repository;

import com.xca.is.entity.YellowDate;
import com.xca.is.service.YellowDateService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class YellowDateRepository {
    private static final String URL = "https://apis.tianapi.com/" ;
    private static final String KEY = "494dec28699ea11966d3ddf914f7cf9f" ;
    private YellowDateService service ;

    public YellowDateRepository(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URL)
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build() ;
        service = retrofit.create(YellowDateService.class) ;
    }

    public Observable<YellowDate> getData(String date){
        return service.getData(KEY,date)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io()) ;
    }
}
